<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class About extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
	public function index()
	{
		if($this->session->userdata('admin_logged_in') == FALSE){
			redirect(base_url()."admin/login");
			exit();
		}
		
		$this->load->model('admin/about_model','about_model');
		$result['info'] = $this->about_model->get_info();
		
		$data['menu_1'] = '';
		$data['menu_2'] = '';
		$data['menu_3'] = '';
		$data['menu_4'] = '';
		$data['menu_5'] = 'current';
		$this->load->view('admin/b_header_view');
		$this->load->view('admin/b_menu_view',$data);
		$this->load->view('admin/b_about_view',$result);
		$this->load->view('admin/b_footer_view');
	}
	
	public function edit_process()
	{
		if($this->session->userdata('admin_logged_in') == FALSE){
			redirect(base_url()."admin/login");
			exit();
		}
			
		if(isset($_FILES["img"]) && is_uploaded_file($_FILES["img"]["tmp_name"]) && $_FILES["img"]["tmp_name"]!=''){
			$this->load->model('admin/about_model','about_model');
			$this->load->library('ciupload');
			$this->ciupload->Upload($_FILES['img']);
			if ($this->ciupload->uploaded){
				$this->ciupload->image_resize = true;
				$this->ciupload->image_ratio_fill = true;
				$this->ciupload->image_x = 387;
				$this->ciupload->image_y = 465;
				$this->ciupload->Process(APPPATH.'../assets/image/about');
				
				if ($this->ciupload->processed){
					$input['id'] = 1;
					$input['img'] = $this->ciupload->file_dst_name;
					$old_img = $this->about_model->get_img();
					$result = $this->about_model->update_img($input);
					if($result==0){
						@unlink(APPPATH.'../assets/image/about/'.$this->ciupload->file_dst_name);
					}else{
						if($old_img->a_path!='' AND file_exists(APPPATH.'../assets/image/about/'.$old_img->a_path)){
							@unlink(APPPATH.'../assets/image/about/'.$old_img->a_path);
						}
					}
				}
				$this->ciupload->clean();
			}
			redirect(base_url()."admin/about");
		}else{
			redirect(base_url()."admin/about");
		}
	}
}

/* End of file chou_a_la_creme.php */
/* Location: ./application/controllers/admin/chou_a_la_creme.php */